var Element;
if (!Element) {
	Element = {};
}
function $(id) {
	if(! id){
		return null;
	}
	if (id.tagName) {
		return id;
	}
	return document.getElementById(id);
}
var BrowserType = {
	IE : !!(window.attachEvent && !window.opera),
	Opera : !!window.opera,
	WebKit : navigator.userAgent.indexOf("AppleWebKit/") > -1,
	Gecko : navigator.userAgent.indexOf("Gecko") > -1
			&& navigator.userAgent.indexOf("KHTML") == -1,
	MobileSafari : !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
};
if (!document.viewport) {
	document.viewport = {};
}
document.viewport.getScrollOffsets = function() {
	return Element._returnOffset(window.pageXOffset
			|| document.documentElement.scrollLeft || document.body.scrollLeft,
			window.pageYOffset || document.documentElement.scrollTop
					|| document.body.scrollTop);
};
var syAjax;
if (!syAjax) {
	syAjax = {};
}
syAjax.namespace = function() {
	var a = arguments, o = null, i, j, d;
	for (i = 0; i < a.length; i = i + 1) {
		d = a[i].split(".");
		o = Handson;
		for (j = (d[0] == "Terry") ? 1 : 0; j < d.length; j = j + 1) {
			o[d[j]] = o[d[j]] || {};
			o = o[d[j]];
		}
	}
	return o;
};

syAjax.request = function(method, url, postContent, callback, isAsy) {
	var xmlhttp;
	if (!isAsy) {
		isAsy = true;
	}
	if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				if (callback.type == "plain") {
					callback.success(xmlhttp.responseText);
				} else {
					callback.success(xmlhttp.responseXML);
				}
			} else {
				callback.fail();
			}
		}
	};
	if (method.toLowerCase() == "get") {
		xmlhttp.open("get", url + "?" + postContent, isAsy);
		xmlhttp.send(null);
	} else {
		xmlhttp.open("post", url, true);
		xmlhttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		xmlhttp.send(postContent);
	}
};
function onFail(){
	alert("ajax error");
}


var Event;
if (!Event) {
	Event = {};
}

Event.stop = function(e) {
	if (!e) {
		return;
	}
	if (e.stopPropagation) {
		e.stopPropagation();
	} else {
		e.cancelBubble = true;
	}
	if (e.preventDefault) {
		e.preventDefault();
	} else {
		e.returnValue = false;
	}
};
Event.addListener = function(target, eventType, handler) {
	var length = arguments.length;
	var params = new Array();
	for (var index = 3; index < length; index++) {
		params.push(arguments[index]);
	}

	var proxyHandler = function(event) {
		handler(event, params);
	}
	handler.proxyHandler = proxyHandler;

	if (document.attachEvent) {
		target.attachEvent("on" + eventType, proxyHandler);
	} else {
		if (document.addEventListener) {
			target.addEventListener(eventType, proxyHandler, false);
		} else {
			target["on" + eventType] = proxyHandler;
		}
	}
};
Event.removeListener = function(target, eventType, handler) {
	if (handler.proxyHandler) {
		handler = handler.proxyHandler;
	}
	if (document.detachEvent) {
		target.detachEvent("on" + eventType, handler);
	} else {
		if (document.removeEventListener) {
			target.removeEventListener(eventType, handler, false);
		} else {
			target["on" + eventType] = null;
		}
	}
};
Event.target = function(event) {
	if (event.srcElement) {
		return event.srcElement;
	} else {
		return event.target;
	}
};
Event.onDOMReady = function(fun) {
	Event.addListener(window, "load", fun);
};

function displayPage(objURL,pageInfo){
	var pageControlLinks = $("pageInfoEl").getElementsByTagName("A");
	var length = pageControlLinks.length;
	for(var index=0;index<length;index++){
   		Event.addListener(pageControlLinks[index],"click", goPage);
   	}
   	var pageNo = pageInfo.pageNo || 0;
    var pageSize = pageInfo.pageSize || 60;
    var totalCount = pageInfo.totalCount || 0;
    var totalPageNumber = pageInfo.pageCount;
   
   	if(pageNo == 0){
   		$("backPage").className = "disable";
   	}
   	if(pageNo == (totalPageNumber - 1) || pageInfo.pageCount == 0){
   		$("nextPage").className = "disable";
   	}    	
  	
  	function goPage(event, params){    	
    	Event.stop(event);
    	var eventEl = Event.target(event);	    	
    	var action = Number(params[0]);
    	var pageA = Event.target(event).id;
    	if(pageA == "backPage"){
    		pageNo = (pageNo == 0? 0:pageNo-1);
    	}
    	if(pageA == "nextPage"){
    		pageNo = (pageNo == totalPageNumber-1? pageNo: pageNo+1);
    	}
    	if(pageA.indexOf("page") != -1){
    		pageNo = pageA.substring(4) - 1;
    	}
    	if(pageNo == pageInfo.pageNo || pageInfo.pageCount == 0){
    		return;
    	}	    	
   		var queryURL = objURL+"&pageSize="+pageInfo.pageSize+"&pageNo="+pageNo;
    	location.href = queryURL;	    	
   	}
}

var Anim;
if (!Anim) {
	Anim = {}
}
Anim.show = function(el, callback){
	if(! el){
		return;
	}
	var opacityValue = 0;
	_fadeIn();
	function _fadeIn(){
		opacityValue += 30;				
		el.style.opacity = opacityValue/100;
		el.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+opacityValue+")";
		if(opacityValue >= 100){
			if(callback){
				callback();
			}
		}else{
			setTimeout(function(){_fadeIn()}, 70);
		}
	}
}
Anim.DD = function(target, dragElement) {
	var preElementPoint = {};
	var mouseDownPoint = {};
	var draggable = false;
	var _self = this;
	function init() {
		if (typeof(target) == "string") {
			target = $(target);
		}

		if (!dragElement) {
			dragElement = target;
		} else if (typeof(dragElement) == "string") {
			dragElement = $(dragElement);
		}

		target.style.position = "absolute";
		Event.addListener(dragElement, "mousedown", startDrag);
		Event.addListener(document, "mouseup", stopDrag);
		Event.addListener(document, "mousemove", drag);
		target.style.top = target.offsetTop + "px";
		target.style.left = target.offsetLeft + "px";
		_self.cancelDD = cancelDD;
		_self.element = target;
	}

	function cancelDD() {
		Event.removeListener(dragElement, "mousedown", startDrag);
		Event.removeListener(document, "mouseup", stopDrag);
		Event.removeListener(document, "mousemove", drag);
	}

	function startDrag(event) {
		document.documentElement.style.cursor = "move";
		preElementPoint.top = parseInt(target.style.top);
		preElementPoint.left = parseInt(target.style.left);

		mouseDownPoint.x = event.clientX;
		mouseDownPoint.y = event.clientY;
		draggable = true;
	}

	function stopDrag(event) {
		if (!draggable) {
			return;
		}
		Event.stop(event);
		draggable = false;
		document.documentElement.style.cursor = "default";
		if (target.reWrap) {
			target.reWrap();
		}
	}

	function drag(event) {
		if (!draggable) {
			return;
		}
		if (event.clientX < 0 || event.clientY < 0) {
			return;
		}
		target.style.left = preElementPoint.left
				+ (event.clientX - mouseDownPoint.x) + "px";
		target.style.top = preElementPoint.top
				+ (event.clientY - mouseDownPoint.y) + "px";
		Event.stop(event);
		if (target.hideWrap) {
			target.hideWrap();
		}
	}

	function getGap(pointFrom, pointTo) {
		var point = {};
		point.x = pointTo.x - pointFrom.x;
		point.y = pointTo.y - pointFrom.y;
		return point;
	}
	init();
};